{% extends 'charts/base.html' %}


{% block options %}
    <ul class="nav ace-nav">
        <li>
            <button class="btn btn-success" id="dl_hy_rank_save" type="button">新增行业动量排行</button>
        </li>
        <li>
            <button class="btn btn-success" id="dl_gn_rank_save" type="button">新增概念动量排行</button>
        </li>
    </ul>
{% endblock %}

{% block sidebar %}
{% endblock %}


{% block content %}
    <div class="widget-box" style="width: 50%; float: left;">
        <div class="widget-header widget-header-flat"><h4 class="widget-title">概念动量排行</h4></div>
        <div class="widget-body">
            {% for day, ranks in gn_ranks.items %}
                <table class="table table-condensed gn_table"
                       style="float: left; width: 31%; margin-left: 20px; font-size: 12px;">
                    <thead>
                    <tr>
                        <td colspan="5" style="font-size: 18px; text-align: center; font-weight: bold;">
                            {{ day }}
                        </td>
                    </tr>
                    <tr style="text-align: center; font-weight: bold;">
                        <td>概念</td>
                        <td>排名</td>
                        <td>评分</td>
                        <td>趋势</td>
                        <td>变化</td>
                        <td>成分</td>
                    </tr>
                    </thead>
                    <tbody>
                    {% for dl in ranks %}
                        <tr class="rank_row" data-name="{{ dl.1.co_name }}">
                            <td>
                                <a class="cf_names" tabindex="0" role="button" data-toggle="popover"
                                   data-trigger="click" title="成份股"
                                   data-content="{% for stock in dl.1.cf_names %} {{ stock }} / {% endfor %} \n {{ dl.1.json_stocks }}">
                                    {{ dl.1.co_name }}
                                </a>
                            </td>
                            <td>{{ dl.1.num }}</td>
                            <td>{{ dl.1.score | floatformat:3 }}</td>
                            <td style="color: {% if dl.1.diff_num > 0 %}red{% elif dl.1.diff_num < 0 %}green{% else %}black{% endif %}">{{ dl.1.diff_num }}</td>
                            <td style="color: {% if dl.1.diff_score > 0 %}red{% elif dl.1.diff_score < 0 %}green{% else %}black{% endif %}">
                                {{ dl.1.diff_score | floatformat:3 }}</td>
                            <td>{{ dl.1.cf_stocks | length }}/{{ dl.1.all_stocks | length }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            {% endfor %}
        </div>
    </div>

    <div class="widget-box" style="width: 50%; float: left;">
        <div class="widget-header widget-header-flat"><h4 class="widget-title">行业动量排行</h4></div>
        <div class="widget-body">
            {% for day, ranks in hy_ranks.items %}
                <table class="table table-condensed hy_table"
                       style="float: left; width: 31%; margin-left: 20px; font-size: 12px;">
                    <thead>
                    <tr>
                        <td colspan="5" style="font-size: 18px; text-align: center; font-weight: bold;">
                            {{ day }}
                        </td>
                    </tr>
                    <tr style="text-align: center; font-weight: bold;">
                        <td>行业</td>
                        <td>排名</td>
                        <td>评分</td>
                        <td>趋势</td>
                        <td>变化</td>
                        <td>成分</td>
                    </tr>
                    </thead>
                    <tbody>
                    {% for dl in ranks %}
                        <tr class="rank_row" data-name="{{ dl.1.hy_name }}">
                            <td>
                                <a class="cf_names" tabindex="0" role="button" data-toggle="popover"
                                   data-trigger="click" title="成份股"
                                   data-content="{% for stock in dl.1.cf_names %} {{ stock }} / {% endfor %} \n {{ dl.1.json_stocks }}">
                                    {{ dl.1.hy_name }}
                                </a>
                            </td>
                            <td>{{ dl.1.num }}</td>
                            <td>{{ dl.1.score | floatformat:3 }}</td>
                            <td style="color: {% if dl.1.diff_num > 0 %}red{% elif dl.1.diff_num < 0 %}green{% else %}black{% endif %}">{{ dl.1.diff_num }}</td>
                            <td style="color: {% if dl.1.diff_score > 0 %}red{% elif dl.1.diff_score < 0 %}green{% else %}black{% endif %}">
                                {{ dl.1.diff_score | floatformat:3 }}</td>
                            <td>{{ dl.1.cf_stocks | length }}/{{ dl.1.all_stocks | length }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            {% endfor %}
        </div>
    </div>

{% endblock %}

{% block js %}
    <script>
        $(
            function () {
                $('.cf_names').popover();

                $('tr.rank_row').hover(function () {
                    $('tr.rank_row').removeClass('warning');
                    var name = $(this).attr('data-name');
                    $('tr.rank_row[data-name="' + name + '"]').addClass('warning');
                });

                // 新增动量排行数据
                $('#dl_hy_rank_save').click(function () {
                    var ranks = prompt('请输入新的动量排行数据：');
                    if (ranks == null) {
                        return false
                    }
                    $.ajax({
                        type: "PSOT",
                        url: "/stock/dl_hy_save",
                        headers: {'X-CSRFToken': '{{ csrf_token }}'},
                        contentType: "application/json",
                        data: ranks,
                        dataType: 'json',
                        success: function (result) {
                            if (result['code'] === 200) {
                                alert('添加成功，请刷新页面');
                            }
                        }
                    });
                    return true
                });
                $('#dl_gn_rank_save').click(function () {
                    var ranks = prompt('请输入新的动量排行数据：');
                    if (ranks == null) {
                        return false
                    }
                    $.ajax({
                        type: "PSOT",
                        url: "/stock/dl_gn_save",
                        headers: {'X-CSRFToken': '{{ csrf_token }}'},
                        contentType: "application/json",
                        data: ranks,
                        dataType: 'json',
                        success: function (result) {
                            if (result['code'] === 200) {
                                alert('添加成功，请刷新页面');
                            }
                        }
                    });
                    return true
                });
            }
        );
    </script>
{% endblock %}